"""
@File    :   out.py
@Time    :   2024/03/25 13:03:48
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   Oauth2客户端相关的pydantic序列化模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, HttpUrl, TypeAdapter

from src.business.admin.system.oauth2.auth.enums import OAuth2GrantTypeEnum
from src.schemas.out import BaseOutSchemaConfigMixin


class Oauth2ClientCompleteOutSchema(BaseModel, BaseOutSchemaConfigMixin):
    """Oauth2客户端完整的序列化模型"""

    id: int = Field(default=..., description="主键")
    status: bool = Field(default=..., description="状态")
    show_order: int = Field(default=..., description="显示顺序")
    remark: str = Field(default=..., description="备注")
    create_datetime: datetime = Field(default=..., description="创建时间")
    update_datetime: datetime = Field(default=..., description="修改时间")
    expiration_datetime: datetime = Field(default=..., description="过期时间")
    creator_username: str = Field(default=..., description="创建者")
    updater_username: str = Field(default=..., description="修改者")
    tenant_id: int = Field(default=..., description="租户ID")
    client_id: str = Field(default=..., description="客户端编号")
    client_secret: str = Field(default=..., description="客户端密钥")
    name: str = Field(default=..., description="应用名")
    logo: str = Field(default=..., description="应用图标")
    access_token_expiration_seconds: int = Field(
        default=..., description="访问令牌过期秒数"
    )  # 最多6小时
    refresh_token_expiration_seconds: int = Field(
        default=..., description="刷新令牌过期秒数"
    )  # 最多15天
    authorization_code_expiration_seconds: int = Field(
        default=..., description="授权码过期秒数"
    )  # 默认10分钟, 最多15分钟
    redirect_uris: list[HttpUrl] = Field(default=..., description="可重定向的URI地址")
    authorized_grant_types: list[OAuth2GrantTypeEnum] = Field(
        default=..., description="oauth2授权类型"
    )
    scopes: list[str] = Field(default=..., description="oauth2授权范围")
    auto_approve_scopes: list[str] = Field(
        default=..., description="自动赋予的oauth2授权范围"
    )
    additional_information: str = Field(default=..., description="附加信息")
    is_init: bool = Field(default=..., description="是否初始创建的Oauth2客户端")


# 完整的Oauth2客户端序列化列表模型
ListOauth2ClientCompleteOutSchema = TypeAdapter(list[Oauth2ClientCompleteOutSchema])
